#{extends 'admin.html' /}
#{set title:'Administration : Edition d\'un Utilisateur' /}
<article class="module width_full">
    <header><h3 class="tabs_involved">Edition de l'utilisateur : ${entity.firstname} ${entity.lastname}</h3>
        <ul class="tabs">
            <li><a href="@{Users.list}">Annuler</a></li>
            <li><a href="#">Réinitialiser le mot de passe</a></li>
            <li><a href="#">Transformer en Client</a></li>
        </ul>
    </header>

    <div class="entity">
        #{form @Users.update(), id:'createForm'}
        <div class="module_content">
            <fieldset>
                <label>Prénom : </label>
                <input type="text" name="entity.firstname" value="${entity?.firstname}"/>
                <span class="error">${errors.forKey('entity.firstname')}</span>
            </fieldset>
            <fieldset>
                <label>Nom : </label>
                <input type="text" name="entity.lastname" value="${entity?.lastname}"/>
                <span class="error">${errors.forKey('entity.lastname')}</span>
            </fieldset>
            <fieldset>
                <label>Date de Naissance : </label>
                <input id="birthday" type="date" name="entity.birthday" 
                       value="${entity?.birthday.format()}"
                       size="10" />
                <span class="error">${errors.forKey('entity.birthday')}</span><span>Sous la Forme : jj/mm/aaaa</span>
            </fieldset>
            <fieldset>
                <label>Avatar : </label>
                <input type="text" name="entity.avatar" value="${entity?.avatar}"/>
                <span class="error">${errors.forKey('entity.avatar')}</span>
            </fieldset>
            <fieldset>
                <label>Adresse : </label>
                <input type="text" name="entity.adress" value="${entity?.adress}"/>
                <span class="error">${errors.forKey('entity.adress')}</span>
            </fieldset>
            <fieldset>
                <label>N° de Téléphone : </label>
                <input type="text" name="entity.phonenumber" value="${entity?.phonenumber}"/>
                <span class="error">${errors.forKey('entity.phonenumber')}</span>
            </fieldset>
            <fieldset>
                <label>Courrier Electronique : </label>
                <input type="text" name="entity.email" value="${entity?.email}"/>
                <span class="error">${errors.forKey('entity.email')}</span>
            </fieldset>
            <fieldset>
                <label>Nom d'utilisateur : </label>
                <input type="text" name="entity.username" value="${entity?.username}"/>
                <span class="error">${errors.forKey('entity.username')}</span>
            </fieldset>
            <fieldset>
                <label>Groupe : </label>
                <select name="entity.groups.id">           

                    %{ models.Group.all().fetch().sort{ it.toString() }.each() { }%

                    %{
                    selected = false;
                    if (entity?.groups?.id == it.id) {
                    selected = true
                    }
                    }%
                    <option value="${it?.id}" ${selected ? 'selected'.raw() : ''}>${it}</option>
                    %{ } }%
                </select>
                <span class="error">${errors.forKey('entity.groups')}</span>
            </fieldset>
            <input type="hidden" name="entity.id" value="${entity?.id}"/>
        </div>
        <footer>
            <div class="submit_link">
                <input type="submit" name="submit" value="Enregistrer" class="alt_btn"/>
            </div>
        </footer>
        #{/form}
    </div>
</article>
